//登录 login 页面👇
<template>
<view class="container">
<view class="form-group">
<text>用户名：</text>
<input v-model="username" type="text" placeholder="请输入用户名" />
</view>
 
<view class="form-group">
  <view style="margin-left: 30rpx;"></view>
<text>密码：</text>
<input v-model="password" type="password" placeholder="请输入密码" />
</view>
<view class="btn-login">
<button @click="login">登录--vue2版本</button>
</view>
</view>
</template>
 
<script>
export default {
  data() {
    return {
      //页面上设置的默认账户admin，密码123456
      username: 'admin',
      password: '123456'
    };
  },
  onShow() {
    uni.clearStorageSync('identify')
  },
  methods: {
    login() {
      const username = this.username;
      const password = this.password;
      let identify = '';
 
      // 根据用户名和密码来确定身份
      if (username === 'tom' && password === '123456') {
        identify = 'tom';
      } else if (username === 'admin' && password === '123456') {
        identify = 'admin';
      } else {
        // 用户名或密码错误
        console.log('用户名或密码错误');
        return;
      }
      //本地存储
      uni.setStorageSync('identify', identify);
 
      // 跳转到首页
      uni.switchTab({
        url: '/pages/index/index'
      });
    }
  }
};
</script>
 
<style scoped>
.container {
padding: 30rpx;
}
 
.form-group {
  display: flex;
  align-items: center;
  justify-content: center;
margin-bottom: 30rpx;
}
input{
  border: 1rpx solid #00BAB2;
  padding: 10rpx;
}
button {
background-color: #00BAB2;
color: white;
border: none;
border-radius: 20rpx;
}
</style>